home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / FWRunTyp / Sources / FWClaInf.cpp next >
Encoding:
Text File  |  1994-04-21  |  3.2 KB  |  93 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWClaInf.cpp
  4. //    Release Version:    $ 1.0d1 $
  5. //
  6. //    Creation Date:        3/28/94
  7. //
  8. //    Copyright:    © 1994 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef   FWCLAINF_H
  13. #include "FWClaInf.h"
  14. #endif
  15.  
  16. #ifndef   FWPRIDEB_H
  17. #include "FWPriDeb.h"
  18. #endif
  19.  
  20. #pragma segment FW_ClassInfo
  21.  
  22. //========================================================================================
  23. // CLASS FW_CClassInfo
  24. //========================================================================================
  25.  
  26. //----------------------------------------------------------------------------------------
  27. //    FW_CClassInfo::FW_CClassInfo
  28. //----------------------------------------------------------------------------------------
  29. FW_CClassInfo::FW_CClassInfo(const char *const className,
  30.                             size_t instanceSize, 
  31.                             FW_ClassReference  const *ancestors) :
  32.     fClassName(className),
  33.     fInstanceSize(instanceSize),
  34.     fAncestors(ancestors)
  35. {
  36. }
  37.  
  38. //----------------------------------------------------------------------------------------
  39. //    FW_CClassInfo::~FW_CClassInfo
  40. //----------------------------------------------------------------------------------------
  41.  
  42. FW_CClassInfo::~FW_CClassInfo()
  43. {
  44. }
  45.  
  46. //----------------------------------------------------------------------------------------
  47. //    FW_CClassInfo::IsKindOf
  48. //----------------------------------------------------------------------------------------
  49.  
  50. // (MLH) ??? - We should consider a cache scheme or a preporcessor calculation
  51. // What we really want is a list of all the classes between this and
  52. // the root. This knowledge is known at compile time. For the runtime
  53. // cache case, instead of recursively calling this routine, call a routine
  54. // that builds the list and stores it in a cache.
  55. //
  56. // The list is simply a vector of classinfo pointers and a count. It is much
  57. // faster to scan one vector then to recursively call IsKindOf.
  58. //
  59. // (JEL) ??? - I don't agree with the above.  In order to flatten everything out
  60. // into a vectors, we would have to duplicate a lot of data.  Suppose we have two
  61. // classes X and Y, that each are derived from a deep hierarchy A -> B -> C.  To
  62. // flatten into vectors, we would need two vectors [A,B,C,X] and [A,B,C,Y], duplicating
  63. // the data [A,B,C].  I don't think it makes sense to do tradeoff space for speed.
  64. // In some specific uses it will make sense to cache, but I don't think that belongs
  65. // here.  Perhaps we should take the effort to rewrite this algorithm so that it doesn't
  66. // use this kind of direct recursion, by writing a loop that manipulates an an internal
  67. // stack that contains the state of the search, but I think that is overkill without
  68. // evidence from testing that this function is a bottleneck.
  69.  
  70. FW_Boolean FW_CClassInfo::IsKindOf(FW_ClassReference aBaseClass) const
  71. {
  72.     FW_Boolean result = FALSE;
  73.     
  74.     if (aBaseClass == this)
  75.         result = TRUE;
  76.     else
  77.     {
  78.         FW_ClassReference const *ancestors = fAncestors;
  79.     
  80.         while (*ancestors != 0)
  81.         {
  82.             if ((*ancestors)->IsKindOf(aBaseClass))
  83.             {
  84.                 result = TRUE;
  85.                 break;
  86.             }
  87.             ancestors++;
  88.         }
  89.     }
  90.     return result;
  91. }
  92.  
  93.